package base;

import static util.Constant.STR_INVALID_ID;

/**
 * The Tag {@code class}. Create Tag object with an ID and a name.
 * 
 * @author Peter NGO, Guillaume POUSSEL and Mathieu RUL
 * 
 * @version 1.0
 */
public class Tag {

	/**
	 * ID of the Tag.
	 */
	private Integer ID;

	/**
	 * Name of the Tag.
	 */
	private String name;

	/**
	 * Constructor of the {@code class}. Create a Tag.
	 */
	public Tag() {
		this("Unnamed Tag");
	}

	/**
	 * Constructor of the {@code class}. Create a Tag from an ID.
	 * 
	 * @param ID
	 *            the Tag ID.
	 * 
	 * @throws IllegalArgumentException
	 */
	public Tag(Integer ID) throws IllegalArgumentException {
		if (ID < 0)
			throw new IllegalArgumentException(STR_INVALID_ID);

		this.ID = ID;
	}

	/**
	 * Constructor of the {@code class}. Create a Tag from parameter.
	 * 
	 * @param ID
	 *            the Tag ID.
	 * 
	 * @param name
	 *            the Tag name.
	 * 
	 * @throws IllegalArgumentException
	 */
	public Tag(Integer ID, String name) throws IllegalArgumentException {
		if (ID < 0)
			throw new IllegalArgumentException(STR_INVALID_ID);

		this.ID = ID;
		this.name = name;
	}

	/**
	 * Constructor of the {@code class}. Create a Tag from a name.
	 * 
	 * @param name
	 *            the tag name.
	 */
	public Tag(String name) {
		this(0, name);
	}

	/**
	 * Check equality between two tags.
	 * 
	 * If this method get a Tag, it compares the two IDs, else it returns false.
	 * 
	 * @param object
	 *            Another object to compare.
	 *            
	 * @return {@code true} if the parameter are a Tag; {@code false} otherwise.
	 */
	public boolean equals(Object object) {
		return ((object instanceof Tag) && ((Tag) object).getID() == this.ID);
	}
	
	/**
	 * Return the tag ID.
	 * 
	 * @return Tag ID.
	 */
	public Integer getID() {
		return ID;
	}

	/**
	 * Return the tag name.
	 * 
	 * @return The tag name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Get an hash representation of the Tag.
	 * 
	 * @return the hash representation of the Tag.
	 */
	@Override
	public int hashCode() {
		return null != ID ? ID : 0;
	}

	/**
	 * Set the Tag name.
	 * 
	 * @param name
	 *            The tag name.
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Returns a {@code String} object representing the Tag's value.
	 * 
	 * @return a string representation of the Tag.
	 */
	@Override
	public String toString() {
		return "Tag " + ID + " [" + name + "]";
	}
}
